import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_app_info.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/models/xindong_auth_class.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/user/auth/xindong_auth_ctr.dart';
import 'package:xindong/routes/user/auth/xindong_auth_item_widget.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/dialog/xindong_alert_message.dart';

class XinDongAuthYeMian extends StatelessWidget {
  const XinDongAuthYeMian({super.key});

  void _onTap(XinDongAuthClass model) {
    if (model.status != 0 && model.status != 3) {
      return;
    }
    if (model.data.isNotEmpty && model.data.containsKey("name")) {
      XinDongAlertMessage.show(
        title: "提示",
        content: "${model.data["content"]}",
        button: "${model.data["desc"]}",
        onTapButton: () {
          XinDongPageSingleton.instance.jumpWithName("${model.data["name"]}");
        },
      );
      return;
    }
    XinDongPageSingleton.instance.jumpWithName(model.name);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar("认证"),
      body: CustomScrollView(
        physics: const AlwaysScrollableScrollPhysics(),
        slivers: <Widget>[
          // 提示
          SliverToBoxAdapter(
            child: Container(
              padding: const EdgeInsets.all(15),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(
                    children: [
                      ImageUtil.asset(AssetsRes.ICON_AUTHENTICATION_TIPS, width: 16, height: 16),
                      const SizedBox(width: 5),
                      const Text(
                        "小贴士",
                        style: TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w600,
                          color: DZColors.contentColor,
                        ),
                      ),
                    ],
                  ),
                  Text(
                    "${XinDongAppDeviceInfo.instance.showAppName}，致力于打造安全、真实、优质的交友环境，实名真人认证的用户会得到优先匹配和更多的曝光机会",
                    style: const TextStyle(fontSize: 14, color: DZColors.contentColor, height: 1.8),
                  )
                ],
              ),
            ),
          ),
          GetBuilder<XinDongAuthCtr>(initState: (state) {
            XinDongAuthCtr.to.requestAuthList();
          }, builder: (controller) {
            return SliverFixedExtentList(
              itemExtent: 86.0,
              delegate: SliverChildBuilderDelegate(
                (BuildContext context, int index) {
                  XinDongAuthClass model = controller.dataList[index];
                  return XinDongAuthItemWidget(model: model, onTap: _onTap);
                },
                childCount: controller.dataList.length,
              ),
            );
          }),
        ],
      ),
    );
  }
}
